home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 343_02 / pi.c < prev    next >
C/C++ Source or Header  |  1992-02-27  |  7KB  |  225 lines

  1.  
  2.  
  3.        /*******************************************************
  4.        *
  5.        *       file d:\cips\pi.c
  6.        *
  7.        *       Functions: This file contains
  8.        *           print_image
  9.        *           print_image_array
  10.        *           perform_printing
  11.        *           print_column_header
  12.        *
  13.        *       Purpose - These functions print an image out to the 
  14.        *           line printer.  The parameters in this function
  15.        *           are defined differently than in most other CIPS
  16.        *           functions.  The parameters il, ie, ll, le are
  17.        *           coordinates inside the 100x100 image array.
  18.        *           The parameters first_line and first_element
  19.        *           are coordinates for the entire image file.
  20.        *           So, if you want to start printing at row 10
  21.        *           and column 10 of the image file you would call:
  22.        *
  23.        *           read_tiff_image(name, the_image, 10, 10, 
  24.        *                           110, 110);
  25.        *           print_image(the_image, name, 1, 1, 1, 100, 18,
  26.        *                       10, 10);
  27.        *
  28.        *           In normal print mode you can only print 17 
  29.        *           columns.
  30.        *           le - ie = 17.
  31.        *
  32.        *
  33.        *       External Calls:
  34.        *           fwrite.c - my_frwiteln
  35.        *                      my_fwrite
  36.        *           rstring.c - read_string
  37.        *                       long_clear_buffer
  38.        *
  39.        *       Modifications:
  40.        *           6 January 1987 - created
  41.        *           14 August 1990 - modified to be part of the
  42.        *               C Image Processing System
  43.        *
  44.        *******************************************************/
  45.  
  46. #include "d:\cips\cips.h"
  47. #define  FORMFEED  '\014'
  48.  
  49.  
  50. print_image(the_image, name, channel, il, ie, ll, le,
  51.             first_line, first_element)
  52.    char  name[];
  53.    int   channel, il, ie, ll, le, first_line, first_element;
  54.    short the_image[ROWS][COLS];
  55. {
  56.    char printer_name[MAX_NAME_LENGTH];
  57.    FILE *printer;
  58.  
  59.    strcpy(printer_name, "prn");
  60.    if( (printer = fopen(printer_name, "w")) == NULL)
  61.       printf("\nPI> Could not open printer");
  62.    else{
  63.       printf("\nPI> The print file is opened");
  64.  
  65.                /*****************************************
  66.                *
  67.                *   If your printer has some form of 
  68.                *   condensed printing, you can send those
  69.                *   commands via software using the fputc
  70.                *   function.  For example, if your printer
  71.                *   needs to sequence X Y Z to start 
  72.                *   condensed printing, insert the following
  73.                *   three calls right here:
  74.                *   fputc('X', printer);
  75.                *   fputc('Y', printer);
  76.                *   fputc('Z', printer);
  77.                *
  78.                ********************************************/
  79.  
  80.       perform_printing(printer, the_image, name, channel,
  81.                        il, ll, ie, le, first_line, first_element);
  82.       fclose(printer);
  83.    }  /* ends else print  */
  84. }     /* ends print_image  */
  85.  
  86.  
  87. perform_printing(printer, the_image, name, channel,
  88.                  il, ll, ie, le, first_line, first_element)
  89.    char  name[];
  90.    FILE  *printer;
  91.    int         channel, il, ie, ll, le, first_line, first_element;
  92.    short the_image[ROWS][COLS];
  93. {
  94.    char output[3*COLS],
  95.         response[80],
  96.         string[3*COLS];
  97.    int  i,
  98.         j,
  99.         k,
  100.         line_counter;
  101.  
  102.  
  103.    printf("\nPI> Print header");
  104.    line_counter = 0;
  105.    long_clear_buffer(string);
  106.    sprintf(string, "     This image is -- %s --", name);
  107.    my_fwriteln(printer, string);
  108.    ++line_counter;
  109.  
  110.    long_clear_buffer(string);
  111.    sprintf(string, "     The parameters are:");
  112.    my_fwriteln(printer, string);
  113.    ++line_counter;
  114.  
  115.    long_clear_buffer(string);
  116.    sprintf(string, "     channel=%d il=%d ll=%d ie=%d le=%d",
  117.            channel, first_line, first_line+ll-2,
  118.            first_element, first_element+le-2);
  119.    my_fwriteln(printer, string);
  120.    ++line_counter;
  121.  
  122.    long_clear_buffer(string);
  123.    sprintf(string, " ");
  124.    my_fwriteln(printer, string);
  125.    ++line_counter;
  126.  
  127.    print_column_header(&line_counter, first_element, ie, le, 
  128.                        output, string, printer);
  129.  
  130.    for(i=il; i<ll; i++){
  131.  
  132.       long_clear_buffer(string);
  133.  
  134.         /* now print the image  */
  135.       sprintf(string, "      ");
  136.       long_clear_buffer(output);
  137.       sprintf(output, "%3d-", i+first_line-1);
  138.       append_string(output, string);
  139.       for(j=ie; j<le; j++){
  140.          long_clear_buffer(output);
  141.          sprintf(output,"%4d",the_image[i][j]);
  142.          append_string(output, string);
  143.       }  /* ends loop over j columns */
  144.  
  145.       my_fwriteln(printer, string);
  146.       line_counter = line_counter + 1;
  147.       if(line_counter >= 53){
  148.          line_counter = 0;
  149.          putc(FORMFEED, printer);
  150.          print_column_header(&line_counter, first_element, ie,
  151.                              le, output, string, printer);
  152.       }  /* ends if line_counter >=65  */
  153.    }  /* ends loop over i rows */
  154.  
  155.    for(i=line_counter; i<66; i++){
  156.       long_clear_buffer(string);
  157.       sprintf(string, " ");
  158.       my_fwriteln(printer, string);
  159.    }
  160.  
  161. }     /* ends perform_printing  */
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172. print_column_header(line_counter, first_element, ie, le, output,
  173.                     string, printer)
  174.    char string[], output[];
  175.    FILE *printer;
  176.    int  first_element, ie, le, *line_counter;
  177. {
  178.    int k;
  179.  
  180.    long_clear_buffer(string);
  181.    sprintf(string, "          ");
  182.  
  183.  
  184.    for(k=first_element; k<(first_element + (le-ie)); k++){
  185.       long_clear_buffer(output);
  186.       sprintf(output, "-%3d", k);
  187.       append_string(output, string);
  188.    }  /* ends loop over k  */
  189.    my_fwriteln(printer, string);
  190.    *line_counter = *line_counter + 1;
  191. }  /* ends print_column_header  */
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.        /****************************************************
  202.        *
  203.        *   print_image_array(...
  204.        *
  205.        *   This function prints a 100x100 image array.
  206.        *
  207.        ****************************************************/
  208.  
  209. print_image_array(the_image)
  210.    short the_image[ROWS][COLS];
  211. {
  212.    char response[80];
  213.    printf("\nPIA> Enter a comment line\n--");
  214.    clear_buffer(response);
  215.    read_string(response);
  216.                                 /*     il  ie  ll    le    */
  217.    print_image(the_image, response, 0,  1,  1, 100,  17, 0, 0);
  218.    print_image(the_image, response, 0,  1, 18, 100,  35, 0, 0);
  219.    print_image(the_image, response, 0,  1, 36, 100,  53, 0, 0);
  220.    print_image(the_image, response, 0,  1, 54, 100,  71, 0, 0);
  221.    print_image(the_image, response, 0,  1, 72, 100,  89, 0, 0);
  222.    print_image(the_image, response, 0,  1, 90, 100, 100, 0, 0);
  223.  
  224. }  /* ends print_image_array  */
  225.